/*
 * @Author: 千锋爱佛僧
 * @公众号: 大前端私房菜
 * @Slogan: 千锋精品教程，好学得不像实力派！
 */
import { defineStore } from "pinia";
import { userLogin } from "../api/user";
import { AccountType, UserInfoType } from "../types/user";
import router from "../router";
interface AccountStateType {
  userInfo: UserInfoType | null;
}
export const useAccount = defineStore("user", {
  state: (): AccountStateType => ({
    userInfo: null,
  }),
  actions: {
    async loginAction(account: AccountType) {
      let res = await userLogin(account);
      console.log("登录成功", res);
      let { status, data } = res;
      if (status == 200) {
        this.userInfo = data;
        router.push("/");
      }
    },
  },
  persist: {
    key: "vite-vue-2301",
  },
});
